import 'package:base/main.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:module_home/pages/more_manage/more_manager_logic.dart';
import 'package:module_home/pages/more_manage/widget/more_function_view/draggable_grid_item.dart';

/// 首页功能区
class MoreFunctionWidget extends StatelessWidget {
  final MoreManagerLogic logic;

  const MoreFunctionWidget({super.key, required this.logic});

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => GridView.builder(
        padding: EdgeInsets.zero,
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 5,
          childAspectRatio: 1.2,
          crossAxisSpacing: 4,
          mainAxisSpacing: 4,
        ),
        itemCount: logic.functionItems.length,
        itemBuilder: (context, index) => Obx(() => DraggableGridItem(
              data: logic.functionItems[index],
              index: index,
              isEditing: logic.isEditing,
              onDelete: () => logic.deleteItemData(logic.functionItems[index]),
              onReorder: (fromIndex) => logic.insertFunctionItem(fromIndex, index),
            )),
      ),
    );
  }
}
